package com.zlcx.tz.live.repository;

import com.zlcx.tz.live.domain.LiveAgoraAcount;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import javax.transaction.Transactional;
import java.util.Date;

/**
 * <p></p>
 * <PRE>
 * <BR>    修改记录
 * <BR>-----------------------------------------------
 * <BR>    修改日期         修改人          修改内容
 * </PRE>
 *
 * @author zl
 * @version 1.0
 * @date Created in 2019/5/22 09:10
 * @copyright: Copyright (c) founders
 */
@Repository
public interface LiveAgoraAcountRepository extends JpaRepository<LiveAgoraAcount, Long>, JpaSpecificationExecutor<LiveAgoraAcount> {

    LiveAgoraAcount findFirstByUseState(Integer useState);

    LiveAgoraAcount findFirstByAppId(String appId);

    @Transactional(rollbackOn=Exception.class)
    @Modifying(clearAutomatically = true)
    @Query(value = "UPDATE live_agora_acount SET use_state ='0' ,update_time =:updateTime WHERE use_state ='2' AND app_id !=:appId ",nativeQuery = true)
    int abandonActiveAcount(@Param("appId")String appId,@Param("updateTime")Date updateTime);

}
